/*
 * Yet Another Haxe Library, Copyright (c) 2009, Jean-Philippe CIMAN (Jeanffy)
 * All rights reserved.
 * Permission is hereby granted to use, copy, modify, and distribute this
 * source code, or portions hereof, for any purpose, without fee, subject
 * to the following restrictions:
 *
 * 1. The origin of this source code must not be misrepresented.
 * 2. Altered versions must be plainly marked as such and
 *    must not be misrepresented as being the original source.
 * 3. This copyright notice may not be removed or altered from
 *    any source or altered source distribution.
 *
 * If you use this source code in a product, acknowledgment is not
 * required but would be appreciated.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE PROJECT AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
/**
	This class represents a circle
**/
class YahCircle
{
	public var center:YahPoint;
	public var radius:Float;
	
	public function new(?x:Float, ?y:Float, ?_radius:Float)
	{
		/** warning : we consider that if x is provided, y is too **/
		if (x != null)
			center = new YahPoint(x, y);
		else
			center = new YahPoint();
		radius = 0;
		if (_radius != null)
			radius = _radius;
	}
	
	/** Defines the circle **/
	public function set(x:Float, y:Float, r:Float)
	{
		center.set(x, y);
		radius = r;
	}
	
	/** Tests if the circle is in a rectangle area **/
	public function isInRect(xmin:Float, ymin:Float, xmax:Float, ymax:Float) : Bool
	{
		if (center.x > xmax + radius)
			return false;
		if (center.x < xmin - radius)
			return false;
		if (center.y > ymax + radius)
			return false;
		if (center.y < ymin - radius)
			return false;
		return true;
	}
	
	/** Tests if the circle is in a rectangle area **/
	public function isInRect2(rect:YahRect) : Bool
	{
		return isInRect(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
	}
	
#if debug
	/** Debug only. Traces the circle **/
	public function dump()
	{
		trace("YahCircle : (" + center.x + ", " + center.y + ") " + radius);
	}
#end
}
